<!DOCTYPE html>
<html lang="zh-CN" dir="ltr">
    <head><meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'><meta name='description' content='准备（GNU/Linux Debian/Ubuntu） 安装构建环境所需的应用程序。 sudo apt-get install \ binutils \ debootstrap \ squashfs-tools \ xorriso \ grub-pc-bin \ grub-efi-amd64-bin \ mtools mkdir $HOME/live-ubuntu-from-scratch 引导程序 构建基础系统 sudo'>
<title>custom linux live</title>

<link rel='canonical' href='/p/custom-linux-live/'>

<link rel="stylesheet" href="/scss/style.min.56b4b4efdee21dd7cd9a6ec6cdb1882f71985765df9c7591a90716c58b48f4c5.css"><meta property='og:title' content='custom linux live'>
<meta property='og:description' content='准备（GNU/Linux Debian/Ubuntu） 安装构建环境所需的应用程序。 sudo apt-get install \ binutils \ debootstrap \ squashfs-tools \ xorriso \ grub-pc-bin \ grub-efi-amd64-bin \ mtools mkdir $HOME/live-ubuntu-from-scratch 引导程序 构建基础系统 sudo'>
<meta property='og:url' content='/p/custom-linux-live/'>
<meta property='og:site_name' content='良宏'>
<meta property='og:type' content='article'><meta property='article:section' content='Post' /><meta property='article:tag' content='custom' /><meta property='article:tag' content='live' /><meta property='article:published_time' content='2022-05-04T13:14:17&#43;08:00'/><meta property='article:modified_time' content='2022-05-04T13:14:17&#43;08:00'/>
<meta name="twitter:title" content="custom linux live">
<meta name="twitter:description" content="准备（GNU/Linux Debian/Ubuntu） 安装构建环境所需的应用程序。 sudo apt-get install \ binutils \ debootstrap \ squashfs-tools \ xorriso \ grub-pc-bin \ grub-efi-amd64-bin \ mtools mkdir $HOME/live-ubuntu-from-scratch 引导程序 构建基础系统 sudo">
    </head>
    <body class="
    article-page
    ">
    <script>
        (function() {
            const colorSchemeKey = 'StackColorScheme';
            if(!localStorage.getItem(colorSchemeKey)){
                localStorage.setItem(colorSchemeKey, "auto");
            }
        })();
    </script><script>
    (function() {
        const colorSchemeKey = 'StackColorScheme';
        const colorSchemeItem = localStorage.getItem(colorSchemeKey);
        const supportDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches === true;

        if (colorSchemeItem == 'dark' || colorSchemeItem === 'auto' && supportDarkMode) {
            

            document.documentElement.dataset.scheme = 'dark';
        } else {
            document.documentElement.dataset.scheme = 'light';
        }
    })();
</script>
<div class="container main-container flex on-phone--column extended"><aside class="sidebar left-sidebar sticky ">
    <button class="hamburger hamburger--spin" type="button" id="toggle-menu" aria-label="切换菜单">
        <span class="hamburger-box">
            <span class="hamburger-inner"></span>
        </span>
    </button>

    <header>
        
            
            <figure class="site-avatar">
                <a href="/">
                
                    
                    
                    
                        
                        <img src="/img/wx_150x150_hub08581134c092243b209205c3073808c_6075_300x0_resize_q75_box.jpeg" width="300"
                            height="300" class="site-logo" loading="lazy" alt="Avatar">
                    
                
                </a>
                
                    <span class="emoji">🍥</span>
                
            </figure>
            
        
        
        <div class="site-meta">
            <h1 class="site-name"><a href="/">良宏</a></h1>
            <h2 class="site-description">好好学习，天天向上。</h2>
        </div>
    </header><ol class="menu" id="main-menu">
        
        
        
        <li >
            <a href='/' >
                
                
                
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-home" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <polyline points="5 12 3 12 12 3 21 12 19 12" />
  <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7" />
  <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6" />
</svg>



                
                <span>Home</span>
            </a>
        </li>
        
        
        <li >
            <a href='/about/' >
                
                
                
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-user" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="12" cy="7" r="4" />
  <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" />
</svg>



                
                <span>About</span>
            </a>
        </li>
        
        
        <li >
            <a href='/archives/' >
                
                
                
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-archive" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <rect x="3" y="4" width="18" height="4" rx="2" />
  <path d="M5 8v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-10" />
  <line x1="10" y1="12" x2="14" y2="12" />
</svg>



                
                <span>Archives</span>
            </a>
        </li>
        
        
        <li >
            <a href='/search/' >
                
                
                
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-search" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="10" cy="10" r="7" />
  <line x1="21" y1="21" x2="15" y2="15" />
</svg>



                
                <span>Search</span>
            </a>
        </li>
        

        <div class="menu-bottom-section">
            
            
                <li id="dark-mode-toggle">
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-toggle-left" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="8" cy="12" r="2" />
  <rect x="2" y="6" width="20" height="12" rx="6" />
</svg>



                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-toggle-right" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="16" cy="12" r="2" />
  <rect x="2" y="6" width="20" height="12" rx="6" />
</svg>



                    <span>暗色模式</span>
                </li>
            
        </div>
    </ol>
</aside>

    

            <main class="main full-width">
    <article class="main-article">
    <header class="article-header">

    <div class="article-details">
    
    <header class="article-category">
        
            <a href="/categories/tech/" style="background-color: blueviolet; color: #fff;">
                Tech
            </a>
        
            <a href="/categories/command/" style="background-color: brown; color: #fff;">
                Command
            </a>
        
            <a href="/categories/tool/" style="background-color: #0177b8; color: #fff;">
                Tool
            </a>
        
    </header>
    

    <div class="article-title-wrapper">
        <h2 class="article-title">
            <a href="/p/custom-linux-live/">custom linux live</a>
        </h2>
    
        
    </div>

    
    
    
    
    <footer class="article-time">
        
            <div>
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-calendar-time" width="56" height="56" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <path d="M11.795 21h-6.795a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4" />
  <circle cx="18" cy="18" r="4" />
  <path d="M15 3v4" />
  <path d="M7 3v4" />
  <path d="M3 11h16" />
  <path d="M18 16.496v1.504l1 1" />
</svg>
                <time class="article-time--published">May 04, 2022</time>
            </div>
        

        
            <div>
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-clock" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="12" cy="12" r="9" />
  <polyline points="12 7 12 12 15 15" />
</svg>



                <time class="article-time--reading">
                    阅读时长: 5 分钟
                </time>
            </div>
        
    </footer>
    

    
</div>

</header>

    <section class="article-content">
    
    
    <h1 id="准备gnulinux-debianubuntu">准备（GNU/Linux Debian/Ubuntu）</h1>
<p>安装构建环境所需的应用程序。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo apt-get install <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    binutils <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    debootstrap <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    squashfs-tools <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    xorriso <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    grub-pc-bin <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    grub-efi-amd64-bin <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    mtools
</span></span><span class="line"><span class="cl">mkdir <span class="nv">$HOME</span>/live-ubuntu-from-scratch
</span></span></code></pre></div><h1 id="引导程序">引导程序</h1>
<h2 id="构建基础系统">构建基础系统</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo debootstrap <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   --arch<span class="o">=</span>amd64 <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   --variant<span class="o">=</span>minbase <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   22.04 <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   <span class="nv">$HOME</span>/live-ubuntu-from-scratch/chroot <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   https://mirrors.aliyun.com/ubuntu/
</span></span></code></pre></div><p><code>debootstrap</code> 用于从头开始创建 <code>Debian</code> 基础系统，而不需要<code>dpkg</code>或<code>apt</code>的可用性。它通过从镜像站点下载 <code>.deb</code> 文件并将其解压缩到最终可以chroot到的目录中来做到这一点。</p>
<h2 id="外部挂载点">外部挂载点</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo mount --bind /dev <span class="nv">$HOME</span>/live-ubuntu-from-scratch/chroot/dev
</span></span><span class="line"><span class="cl">sudo mount --bind /run <span class="nv">$HOME</span>/live-ubuntu-from-scratch/chroot/run
</span></span></code></pre></div><p>由于将更新和安装的一些软件包（其中包括grub），这些挂载点在chroot环境中是必需的。</p>
<h2 id="定义-chroot-环境">定义 chroot 环境</h2>
<p>Unix操作系统上的<a class="link" href="https://en.wikipedia.org/wiki/Chroot"  target="_blank" rel="noopener"
    >chroot</a>是一种更改当前运行进程及其子进程的明显根目录的操作。在这种修改后的环境中运行的程序无法命名（因此通常无法访问）指定目录树之外的文件。术语“chroot”可以指 <code>chroot</code> 系统调用或 <code>chroot</code> 包装程序。修改后的环境称为 <code>chroot jail</code>。</p>
<h2 id="访问chroot环境">访问chroot环境</h2>
<p><code>sudo chroot $HOME/live-ubuntu-from-scratch/chroot</code></p>
<h2 id="配置挂载点家庭和语言环境">配置挂载点、家庭和语言环境</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">挂载无 -t proc /proc
</span></span><span class="line"><span class="cl">挂载无 -t sysfs /sys
</span></span><span class="line"><span class="cl">挂载无 -t devpts /dev/pts
</span></span><span class="line"><span class="cl">导出 <span class="nv">HOME</span><span class="o">=</span>/root
</span></span><span class="line"><span class="cl">导出 <span class="nv">LC_ALL</span><span class="o">=</span>C
</span></span><span class="line"><span class="cl">这些挂载点在chroot环境中是必需的，因此我们能够顺利完成安装。
</span></span></code></pre></div><p>设置自定义主机名
<code>echo &quot;ubuntu-fs-live&quot; &gt; /etc/hostname</code></p>
<h2 id="配置-apt-sourceslist">配置 apt sources.list</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">cat <span class="s">&lt;&lt;EOF &gt; /etc/apt/sources.list
</span></span></span><span class="line"><span class="cl"><span class="s">deb http://us.archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse 
</span></span></span><span class="line"><span class="cl"><span class="s">deb-src http://us.archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
</span></span></span><span class="line"><span class="cl"><span class="s">deb http://us.archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse 
</span></span></span><span class="line"><span class="cl"><span class="s">deb-src http://us.archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
</span></span></span><span class="line"><span class="cl"><span class="s">deb http://us.archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse 
</span></span></span><span class="line"><span class="cl"><span class="s">deb-src http://us.archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse    
</span></span></span><span class="line"><span class="cl"><span class="s">EOF</span>
</span></span></code></pre></div><h2 id="更新包索引">更新包索引</h2>
<p><code>apt-get update</code></p>
<h2 id="安装systemd">安装<code>systemd</code></h2>
<p><code>apt-get install -y libterm-readline-gnu-perl systemd-sysv</code>
systemd是 Linux 的系统和服务管理器。它提供了积极的并行化能力，使用套接字和 D-Bus 激活来启动服务，提供守护进程的按需启动，使用 Linux 控制组跟踪进程，维护挂载和自动挂载点，并实现精细的基于事务依赖的服务控制逻辑。</p>
<h2 id="配置-machine-id-并转移">配置 <code>machine-id</code> 并转移</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">dbus-uuidgen &gt; /etc/machine-id
</span></span><span class="line"><span class="cl">ln -fs /etc/machine-id /var/lib/dbus/machine-id
</span></span></code></pre></div><blockquote>
<p>该/etc/machine-id文件包含在安装或引导期间设置的本地系统的唯一机器 ID。机器 ID 是一个以换行符结尾的十六进制 32 个字符的小写 ID。从十六进制解码时，这对应于 16 字节/128 位值。此 ID 可能并非全为零。</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">dpkg-divert --local --rename --add /sbin/initctl
</span></span><span class="line"><span class="cl">ln -s /bin/true /sbin/initctl
</span></span></code></pre></div><blockquote>
<p>dpkg-divert是用于设置和更新转移列表的实用程序。</p>
</blockquote>
<h2 id="安装-live-system-所需的软件包">安装 Live System 所需的软件包</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">apt-get install -y <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    sudo <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    ubuntu-standard <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    casper <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    lupin-casper <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    discover <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    laptop-detect <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    os-prober <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    network-manager <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    resolvconf <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    net-tools <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    wireless-tools <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    wpagui <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    locales <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    grub-common <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    grub-gfxpayload-lists <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    grub-pc <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    grub-pc-bin <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    grub2-common
</span></span><span class="line"><span class="cl">apt-get install -y --no-install-recommends linux-generic
</span></span></code></pre></div><h2 id="图形安装程序">图形安装程序</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">apt-get install -y <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    ubiquity <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    ubiquity-casper <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    ubiquity-frontend-gtk <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    ubiquity-slideshow-ubuntu <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    ubiquity-ubuntu-artwork
</span></span></code></pre></div><p>安装过程中将出现<code>tui</code>对话框，无需做任何配置修改。</p>
<h2 id="安装窗口管理器">安装窗口管理器</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">apt-get install -y <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    plymouth-theme-ubuntu-logo <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    ubuntu-gnome-desktop <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    ubuntu-gnome-wallpapers
</span></span></code></pre></div><h2 id="安装有用的应用程序">安装有用的应用程序</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">apt-get install -y <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    clamav-daemon <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    terminator <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    apt-transport-https <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    curl <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    vim <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    nano <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>    less
</span></span></code></pre></div><h2 id="安装-visual-studio-code-可选">安装 Visual Studio Code (可选)</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">curl https://packages.microsoft.com/keys/microsoft.asc <span class="p">|</span> gpg --dearmor &gt; microsoft.gpg
</span></span><span class="line"><span class="cl">install -o root -g root -m <span class="m">644</span> microsoft.gpg /etc/apt/trusted.gpg.d/
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s2">&#34;deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main&#34;</span> &gt; /etc/apt/sources.list.d/vscode.list
</span></span><span class="line"><span class="cl">rm microsoft.gpg
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">apt-get update
</span></span><span class="line"><span class="cl">apt-get install -y code
</span></span></code></pre></div><h2 id="安装-google-chrome-可选">安装 Google Chrome (可选)</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub <span class="p">|</span> sudo apt-key add -
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s2">&#34;deb http://dl.google.com/linux/chrome/deb/ stable main&#34;</span> &gt; /etc/apt/sources.list.d/google-chrome.list
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">apt-get update
</span></span><span class="line"><span class="cl">apt-get install google-chrome-stable
</span></span></code></pre></div><h2 id="安装-jdk-可选">安装 JDK (可选)</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">apt-get install -y <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     openjdk-8-jdk <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     openjdk-8-jre
</span></span></code></pre></div><h2 id="移除不需要的应用-可选">移除不需要的应用 (可选)</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">apt-get purge -y <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     transmission-gtk <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     transmission-common <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     gnome-mahjongg <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     gnome-mines <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     gnome-sudoku <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     aisleriot <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     hitori
</span></span></code></pre></div><h2 id="删除不用的软件包">删除不用的软件包</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">apt-get autoremove -y
</span></span></code></pre></div><h1 id="重新配置">重新配置</h1>
<h2 id="生成语言配置">生成语言配置</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">dpkg-reconfigure locales
</span></span><span class="line"><span class="cl"><span class="c1"># 选择语言和默认语言</span>
</span></span></code></pre></div><h2 id="重新配置-resolvconf">重新配置 <code>resolvconf</code></h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">dpkg-reconfigure resolvconf
</span></span></code></pre></div><h2 id="配置网络">配置网络</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">cat <span class="s">&lt;&lt;EOF &gt; /etc/NetworkManager/NetworkManager.conf
</span></span></span><span class="line"><span class="cl"><span class="s">[main]
</span></span></span><span class="line"><span class="cl"><span class="s">rc-manager=resolvconf
</span></span></span><span class="line"><span class="cl"><span class="s">plugins=ifupdown,keyfile
</span></span></span><span class="line"><span class="cl"><span class="s">dns=dnsmasq
</span></span></span><span class="line"><span class="cl"><span class="s">[ifupdown]
</span></span></span><span class="line"><span class="cl"><span class="s">managed=false
</span></span></span><span class="line"><span class="cl"><span class="s">EOF</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">dpkg-reconfigure network-manager
</span></span></code></pre></div><h2 id="清理-chroot-环境">清理 chroot 环境</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># If have installed software</span>
</span></span><span class="line"><span class="cl">truncate -s <span class="m">0</span> /etc/machine-id
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Remove the diversion</span>
</span></span><span class="line"><span class="cl">rm /sbin/initctl
</span></span><span class="line"><span class="cl">dpkg-divert --rename --remove /sbin/initctl
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Clean up</span>
</span></span><span class="line"><span class="cl">apt-get clean
</span></span><span class="line"><span class="cl">rm -rf /tmp/* ~/.bash_history
</span></span><span class="line"><span class="cl">umount /proc
</span></span><span class="line"><span class="cl">umount /sys
</span></span><span class="line"><span class="cl">umount /dev/pts
</span></span><span class="line"><span class="cl"><span class="nb">export</span> <span class="nv">HISTSIZE</span><span class="o">=</span><span class="m">0</span>
</span></span><span class="line"><span class="cl"><span class="nb">exit</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Unbind mount points</span>
</span></span><span class="line"><span class="cl">sudo umount <span class="nv">$HOME</span>/live-ubuntu-from-scratch/chroot/dev
</span></span><span class="line"><span class="cl">sudo umount <span class="nv">$HOME</span>/live-ubuntu-from-scratch/chroot/run
</span></span></code></pre></div><h1 id="映像目录并填充">映像目录并填充</h1>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">cd</span> <span class="nv">$HOME</span>/live-ubuntu-from-scratch
</span></span><span class="line"><span class="cl">mkdir -p image/<span class="o">{</span>casper,isolinux,install<span class="o">}</span>
</span></span><span class="line"><span class="cl">sudo cp chroot/boot/vmlinuz-**-**-generic image/casper/vmlinuz
</span></span><span class="line"><span class="cl">sudo cp chroot/boot/initrd.img-**-**-generic image/casper/initrd
</span></span><span class="line"><span class="cl">sudo cp chroot/boot/memtest86+.bin image/install/memtest86+
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">wget --progress<span class="o">=</span>dot https://www.memtest86.com/downloads/memtest86-usb.zip -O image/install/memtest86-usb.zip
</span></span><span class="line"><span class="cl">unzip -p image/install/memtest86-usb.zip memtest86-usb.img &gt; image/install/memtest86
</span></span><span class="line"><span class="cl">rm image/install/memtest86-usb.zip
</span></span></code></pre></div><h1 id="grub-配置">Grub 配置</h1>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">cd</span> <span class="nv">$HOME</span>/live-ubuntu-from-scratch
</span></span><span class="line"><span class="cl">touch image/ubuntu
</span></span></code></pre></div><h2 id="创建-imageisolinuxgrubcfg">创建 /image/isolinux/grub.cfg</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">cat <span class="s">&lt;&lt;EOF &gt; image/isolinux/grub.cfg
</span></span></span><span class="line"><span class="cl"><span class="s">
</span></span></span><span class="line"><span class="cl"><span class="s">search --set=root --file /ubuntu
</span></span></span><span class="line"><span class="cl"><span class="s">
</span></span></span><span class="line"><span class="cl"><span class="s">insmod all_video
</span></span></span><span class="line"><span class="cl"><span class="s">
</span></span></span><span class="line"><span class="cl"><span class="s">set default=&#34;0&#34;
</span></span></span><span class="line"><span class="cl"><span class="s">set timeout=30
</span></span></span><span class="line"><span class="cl"><span class="s">
</span></span></span><span class="line"><span class="cl"><span class="s">menuentry &#34;Try Ubuntu FS without installing&#34; {
</span></span></span><span class="line"><span class="cl"><span class="s">   linux /casper/vmlinuz boot=casper quiet splash ---
</span></span></span><span class="line"><span class="cl"><span class="s">   initrd /casper/initrd
</span></span></span><span class="line"><span class="cl"><span class="s">}
</span></span></span><span class="line"><span class="cl"><span class="s">
</span></span></span><span class="line"><span class="cl"><span class="s">menuentry &#34;Install Ubuntu FS&#34; {
</span></span></span><span class="line"><span class="cl"><span class="s">   linux /casper/vmlinuz boot=casper only-ubiquity quiet splash ---
</span></span></span><span class="line"><span class="cl"><span class="s">   initrd /casper/initrd
</span></span></span><span class="line"><span class="cl"><span class="s">}
</span></span></span><span class="line"><span class="cl"><span class="s">
</span></span></span><span class="line"><span class="cl"><span class="s">menuentry &#34;Check disc for defects&#34; {
</span></span></span><span class="line"><span class="cl"><span class="s">   linux /casper/vmlinuz boot=casper integrity-check quiet splash ---
</span></span></span><span class="line"><span class="cl"><span class="s">   initrd /casper/initrd
</span></span></span><span class="line"><span class="cl"><span class="s">}
</span></span></span><span class="line"><span class="cl"><span class="s">
</span></span></span><span class="line"><span class="cl"><span class="s">menuentry &#34;Test memory Memtest86+ (BIOS)&#34; {
</span></span></span><span class="line"><span class="cl"><span class="s">   linux16 /install/memtest86+
</span></span></span><span class="line"><span class="cl"><span class="s">}
</span></span></span><span class="line"><span class="cl"><span class="s">
</span></span></span><span class="line"><span class="cl"><span class="s">menuentry &#34;Test memory Memtest86 (UEFI, long load time)&#34; {
</span></span></span><span class="line"><span class="cl"><span class="s">   insmod part_gpt
</span></span></span><span class="line"><span class="cl"><span class="s">   insmod search_fs_uuid
</span></span></span><span class="line"><span class="cl"><span class="s">   insmod chain
</span></span></span><span class="line"><span class="cl"><span class="s">   loopback loop /install/memtest86
</span></span></span><span class="line"><span class="cl"><span class="s">   chainloader (loop,gpt1)/efi/boot/BOOTX64.efi
</span></span></span><span class="line"><span class="cl"><span class="s">}
</span></span></span><span class="line"><span class="cl"><span class="s">EOF</span>
</span></span></code></pre></div><h1 id="创建-manifest">创建 <code>manifest</code></h1>
<p>在接下来的步骤中，清单的创建很重要，因为它告诉我们每个包的哪个版本安装在 Live 版本中，以及哪些包将在将要安装的版本中删除或维护（保留在硬盘中）。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">cd</span> <span class="nv">$HOME</span>/live-ubuntu-from-scratch
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">sudo chroot chroot dpkg-query -W --showformat<span class="o">=</span><span class="s1">&#39;${Package} ${Version}\n&#39;</span> <span class="p">|</span> sudo tee image/casper/filesystem.manifest
</span></span><span class="line"><span class="cl">sudo cp -v image/casper/filesystem.manifest image/casper/filesystem.manifest-desktop
</span></span><span class="line"><span class="cl">sudo sed -i <span class="s1">&#39;/ubiquity/d&#39;</span> image/casper/filesystem.manifest-desktop
</span></span><span class="line"><span class="cl">sudo sed -i <span class="s1">&#39;/casper/d&#39;</span> image/casper/filesystem.manifest-desktop
</span></span><span class="line"><span class="cl">sudo sed -i <span class="s1">&#39;/discover/d&#39;</span> image/casper/filesystem.manifest-desktop
</span></span><span class="line"><span class="cl">sudo sed -i <span class="s1">&#39;/laptop-detect/d&#39;</span> image/casper/filesystem.manifest-desktop
</span></span><span class="line"><span class="cl">sudo sed -i <span class="s1">&#39;/os-prober/d&#39;</span> image/casper/filesystem.manifest-desktop
</span></span></code></pre></div><h2 id="压缩-chroot">压缩 <code>chroot</code></h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">cd</span> <span class="nv">$HOME</span>/live-ubuntu-from-scratch
</span></span><span class="line"><span class="cl"><span class="c1"># 创建 squashfs</span>
</span></span><span class="line"><span class="cl">sudo mksquashfs chroot image/casper/filesystem.squashfs
</span></span><span class="line"><span class="cl"><span class="c1"># 生成 filesystem.size</span>
</span></span><span class="line"><span class="cl"><span class="nb">printf</span> <span class="k">$(</span>sudo du -sx --block-size<span class="o">=</span><span class="m">1</span> chroot <span class="p">|</span> cut -f1<span class="k">)</span> &gt; image/casper/filesystem.size
</span></span></code></pre></div><blockquote>
<p>Squashfs是一个高度压缩的 Linux 只读文件系统。它使用 zlib 压缩来压缩文件、inode 和目录。系统中的 inode 非常小，所有块都被打包以最小化数据开销。支持大于 4K 的块大小，最大支持 64K。
Squashfs旨在用于一般只读文件系统、存档使用（即在可能使用 .tar.gz 文件的情况下）以及需要低开销的受限块设备/内存系统（例如嵌入式系统）。</p>
</blockquote>
<h2 id="创建磁盘说明">创建磁盘说明</h2>
<p>README文件通常可以在 Linux LiveCD 安装光盘上找到，例如 Ubuntu Linux 安装光盘；通常命名为“ README.diskdefines ”并且可以在安装过程中被引用。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">cd</span> <span class="nv">$HOME</span>/live-ubuntu-from-scratch
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Create file image/README.diskdefines</span>
</span></span><span class="line"><span class="cl">cat <span class="s">&lt;&lt;EOF &gt; image/README.diskdefines
</span></span></span><span class="line"><span class="cl"><span class="s">#define DISKNAME  Ubuntu from scratch
</span></span></span><span class="line"><span class="cl"><span class="s">#define TYPE  binary
</span></span></span><span class="line"><span class="cl"><span class="s">#define TYPEbinary  1
</span></span></span><span class="line"><span class="cl"><span class="s">#define ARCH  amd64
</span></span></span><span class="line"><span class="cl"><span class="s">#define ARCHamd64  1
</span></span></span><span class="line"><span class="cl"><span class="s">#define DISKNUM  1
</span></span></span><span class="line"><span class="cl"><span class="s">#define DISKNUM1  1
</span></span></span><span class="line"><span class="cl"><span class="s">#define TOTALNUM  0
</span></span></span><span class="line"><span class="cl"><span class="s">#define TOTALNUM0  1
</span></span></span><span class="line"><span class="cl"><span class="s">EOF</span>
</span></span></code></pre></div><h2 id="为-livecd-创建-iso-映像-bios--uefi">为 LiveCD 创建 ISO 映像 (BIOS + UEFI)</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">cd</span> <span class="nv">$HOME</span>/live-ubuntu-from-scratch/image
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># 创建 grub UEFI 映像</span>
</span></span><span class="line"><span class="cl">grub-mkstandalone <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   --format<span class="o">=</span>x86_64-efi <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   --output<span class="o">=</span>isolinux/bootx64.efi <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   --locales<span class="o">=</span><span class="s2">&#34;&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   --fonts<span class="o">=</span><span class="s2">&#34;&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   <span class="s2">&#34;boot/grub/grub.cfg=isolinux/grub.cfg&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># 创建包含 EFI 引导加载程序的 FAT16 UEFI 引导磁盘映像</span>
</span></span><span class="line"><span class="cl"><span class="o">(</span>
</span></span><span class="line"><span class="cl">   <span class="nb">cd</span> isolinux <span class="o">&amp;&amp;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   dd <span class="k">if</span><span class="o">=</span>/dev/zero <span class="nv">of</span><span class="o">=</span>efiboot.img <span class="nv">bs</span><span class="o">=</span>1M <span class="nv">count</span><span class="o">=</span><span class="m">10</span> <span class="o">&amp;&amp;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   sudo mkfs.vfat efiboot.img <span class="o">&amp;&amp;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   <span class="nv">LC_CTYPE</span><span class="o">=</span>C mmd -i efiboot.img efi efi/boot <span class="o">&amp;&amp;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   <span class="nv">LC_CTYPE</span><span class="o">=</span>C mcopy -i efiboot.img ./bootx64.efi ::efi/boot/
</span></span><span class="line"><span class="cl"><span class="o">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># 创建 grub BIOS 映像</span>
</span></span><span class="line"><span class="cl">grub-mkstandalone <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   --format<span class="o">=</span>i386-pc <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   --output<span class="o">=</span>isolinux/core.img <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   --install-modules<span class="o">=</span><span class="s2">&#34;linux16 linux normal iso9660 biosdisk memdisk search tar ls&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   --modules<span class="o">=</span><span class="s2">&#34;linux16 linux normal iso9660 biosdisk search&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   --locales<span class="o">=</span><span class="s2">&#34;&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   --fonts<span class="o">=</span><span class="s2">&#34;&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   <span class="s2">&#34;boot/grub/grub.cfg=isolinux/grub.cfg&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># 组合可引导的 grub cdboot.img</span>
</span></span><span class="line"><span class="cl">cat /usr/lib/grub/i386-pc/cdboot.img isolinux/core.img &gt; isolinux/bios.img
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># 生成md5sum.txt</span>
</span></span><span class="line"><span class="cl">sudo /bin/bash -c <span class="s2">&#34;(find . -type f -print0 | xargs -0 md5sum | grep -v &#34;</span><span class="se">\.</span>/md5sum.txt<span class="s2">&#34; &gt; md5sum.txt)&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># 使用命令行从镜像目录创建iso</span>
</span></span><span class="line"><span class="cl">sudo xorriso <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -as mkisofs <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -iso-level <span class="m">3</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -full-iso9660-filenames <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -volid <span class="s2">&#34;Ubuntu from scratch&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -output <span class="s2">&#34;../ubuntu-from-scratch.iso&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -eltorito-boot boot/grub/bios.img <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>      -no-emul-boot <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>      -boot-load-size <span class="m">4</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>      -boot-info-table <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>      --eltorito-catalog boot/grub/boot.cat <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>      --grub2-boot-info <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>      --grub2-mbr /usr/lib/grub/i386-pc/boot_hybrid.img <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -eltorito-alt-boot <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>      -e EFI/efiboot.img <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>      -no-emul-boot <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -append_partition <span class="m">2</span> 0xef isolinux/efiboot.img <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -m <span class="s2">&#34;isolinux/efiboot.img&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -m <span class="s2">&#34;isolinux/bios.img&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -graft-points <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>      <span class="s2">&#34;/EFI/efiboot.img=isolinux/efiboot.img&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>      <span class="s2">&#34;/boot/grub/bios.img=isolinux/bios.img&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>      <span class="s2">&#34;.&#34;</span>
</span></span></code></pre></div><h1 id="另一种方法如果前一个失败创建一个混合-iso">另一种方法，如果前一个失败，创建一个混合 ISO</h1>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># 创建 ISOLINUX (syslinux) 启动菜单</span>
</span></span><span class="line"><span class="cl">cat <span class="s">&lt;&lt;EOF&gt; isolinux/isolinux.cfg
</span></span></span><span class="line"><span class="cl"><span class="s">UI vesamenu.c32
</span></span></span><span class="line"><span class="cl"><span class="s">MENU TITLE Boot Menu
</span></span></span><span class="line"><span class="cl"><span class="s">DEFAULT linux
</span></span></span><span class="line"><span class="cl"><span class="s">TIMEOUT 600
</span></span></span><span class="line"><span class="cl"><span class="s">MENU RESOLUTION 640 480
</span></span></span><span class="line"><span class="cl"><span class="s">MENU COLOR border       30;44   #40ffffff #a0000000 std
</span></span></span><span class="line"><span class="cl"><span class="s">MENU COLOR title        1;36;44 #9033ccff #a0000000 std
</span></span></span><span class="line"><span class="cl"><span class="s">MENU COLOR sel          7;37;40 #e0ffffff #20ffffff all
</span></span></span><span class="line"><span class="cl"><span class="s">MENU COLOR unsel        37;44   #50ffffff #a0000000 std
</span></span></span><span class="line"><span class="cl"><span class="s">MENU COLOR help         37;40   #c0ffffff #a0000000 std
</span></span></span><span class="line"><span class="cl"><span class="s">MENU COLOR timeout_msg  37;40   #80ffffff #00000000 std
</span></span></span><span class="line"><span class="cl"><span class="s">MENU COLOR timeout      1;37;40 #c0ffffff #00000000 std
</span></span></span><span class="line"><span class="cl"><span class="s">MENU COLOR msg07        37;40   #90ffffff #a0000000 std
</span></span></span><span class="line"><span class="cl"><span class="s">MENU COLOR tabmsg       31;40   #30ffffff #00000000 std
</span></span></span><span class="line"><span class="cl"><span class="s">LABEL linux
</span></span></span><span class="line"><span class="cl"><span class="s"> MENU LABEL Try Ubuntu FS
</span></span></span><span class="line"><span class="cl"><span class="s"> MENU DEFAULT
</span></span></span><span class="line"><span class="cl"><span class="s"> KERNEL /casper/vmlinuz
</span></span></span><span class="line"><span class="cl"><span class="s"> APPEND initrd=/casper/initrd boot=casper
</span></span></span><span class="line"><span class="cl"><span class="s">LABEL linux
</span></span></span><span class="line"><span class="cl"><span class="s"> MENU LABEL Try Ubuntu FS (nomodeset)
</span></span></span><span class="line"><span class="cl"><span class="s"> MENU DEFAULT
</span></span></span><span class="line"><span class="cl"><span class="s"> KERNEL /casper/vmlinuz
</span></span></span><span class="line"><span class="cl"><span class="s"> APPEND initrd=/casper/initrd boot=casper nomodeset
</span></span></span><span class="line"><span class="cl"><span class="s">EOF</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># 包括 syslinux bios 模块</span>
</span></span><span class="line"><span class="cl">apt install -y syslinux-common <span class="o">&amp;&amp;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>cp /usr/lib/ISOLINUX/isolinux.bin isolinux/ <span class="o">&amp;&amp;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>cp /usr/lib/syslinux/modules/bios/* isolinux/
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># 从镜像目录创建iso</span>
</span></span><span class="line"><span class="cl">sudo xorriso <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -as mkisofs <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -iso-level <span class="m">3</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -full-iso9660-filenames <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -volid <span class="s2">&#34;Ubuntu from scratch&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   -output <span class="s2">&#34;../ubuntu-from-scratch.iso&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span> -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span> -eltorito-boot <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     isolinux/isolinux.bin <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     -no-emul-boot <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     -boot-load-size <span class="m">4</span> <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     -boot-info-table <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     --eltorito-catalog isolinux/isolinux.cat <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span> -eltorito-alt-boot <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     -e /EFI/boot/efiboot.img <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     -no-emul-boot <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>     -isohybrid-gpt-basdat <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span> -append_partition <span class="m">2</span> 0xef EFI/boot/efiboot.img <span class="se">\
</span></span></span><span class="line"><span class="cl"><span class="se"></span>   <span class="s2">&#34;</span><span class="nv">$HOME</span><span class="s2">/live-ubuntu-from-scratch/image&#34;</span>
</span></span></code></pre></div><h1 id="制作可启动的-usb-映像">制作可启动的 USB 映像</h1>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo dd <span class="k">if</span><span class="o">=</span>ubuntu-from-scratch.iso <span class="nv">of</span><span class="o">=</span>&lt;device&gt; <span class="nv">status</span><span class="o">=</span>progress <span class="nv">oflag</span><span class="o">=</span>sync
</span></span></code></pre></div><h1 id="小结">小结</h1>
<p>生成的 ISO 可以在虚拟机中进行测试，例如VirtualBox或写入媒体并从标准 PC 启动。</p>

</section>


    <footer class="article-footer">
    
    <section class="article-tags">
        
            <a href="/tags/custom/">custom</a>
        
            <a href="/tags/live/">live</a>
        
    </section>


    </footer>


    
</article>

    

    

<aside class="related-content--wrapper">
    <h2 class="section-title">相关文章</h2>
    <div class="related-content">
        <div class="flex article-list--tile">
            
                
<article class="">
    <a href="/p/readline/">
        
        

        <div class="article-details">
            <h2 class="article-title">readline</h2>
        </div>
    </a>
</article>

            
                
<article class="">
    <a href="/p/direnv/">
        
        

        <div class="article-details">
            <h2 class="article-title">direnv</h2>
        </div>
    </a>
</article>

            
                
<article class="">
    <a href="/p/fdleak/">
        
        

        <div class="article-details">
            <h2 class="article-title">fdleak</h2>
        </div>
    </a>
</article>

            
                
<article class="">
    <a href="/p/ssh-into-termux/">
        
        

        <div class="article-details">
            <h2 class="article-title">ssh into termux</h2>
        </div>
    </a>
</article>

            
                
<article class="">
    <a href="/p/ssh/">
        
        

        <div class="article-details">
            <h2 class="article-title">ssh</h2>
        </div>
    </a>
</article>

            
        </div>
    </div>
</aside>

     
    
        
    

    <footer class="site-footer">
    <section class="copyright">
        &copy; 
        
            2021 - 
        
        2023 良宏
    </section>
    <section class="powerby">
        Built with <a href="https://gohugo.io/" target="_blank" rel="noopener">Hugo</a>,
        主题 <b><a href="https://github.com/CaiJimmy/hugo-theme-stack" target="_blank" rel="noopener" data-version="3.5.0">Stack</a></b> 由 <a href="https://jimmycai.com" target="_blank" rel="noopener">Jimmy</a> 设计
    </section>
</footer>


    
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    
    <div class="pswp__bg"></div>

    
    <div class="pswp__scroll-wrap">

        
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                
                
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div><script 
                src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"integrity="sha256-ePwmChbbvXbsO02lbM3HoHbSHTHFAeChekF1xKJdleo="crossorigin="anonymous"
                defer
                >
            </script><script 
                src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"integrity="sha256-UKkzOn/w1mBxRmLLGrSeyB4e1xbrp4xylgAWb3M42pU="crossorigin="anonymous"
                defer
                >
            </script><link 
                rel="stylesheet" 
                href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css"crossorigin="anonymous"
            ><link 
                rel="stylesheet" 
                href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css"crossorigin="anonymous"
            >

            </main>
        </div>
        <script 
                src="https://cdn.jsdelivr.net/npm/node-vibrant@3.1.6/dist/vibrant.min.js"integrity="sha256-awcR2jno4kI5X0zL8ex0vi2z&#43;KMkF24hUW8WePSA9HM="crossorigin="anonymous"
                
                >
            </script><script type="text/javascript" src="/ts/main.js" defer></script><script type="text/javascript" src="/ts/custom.js" defer></script>
<script>
    (function () {
        const customFont = document.createElement('link');
        customFont.href = "https://fonts.font.im/css2?family=Lato:wght@300;400;700&display=swap";

        customFont.type = "text/css";
        customFont.rel = "stylesheet";

        
    }());
</script>


    </body>
</html>
